import Toast from '../../component/vant/toast/toast';
const app = getApp();
const api = require('../../api.js');
const util = require("../../utils/util.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    actionSheetHidden: true,
    focus_type: '',
    focus_id: '',
    famous_teacher: [],
    famous_school: [],
    domain: api.xh.downloadDomain,
    teacherTagStyle: util.teacherTagStyles
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var logging = wx.getStorageSync('_logining');
    if (!logging) {
      app.toAuth('/pages/my/my');
    } else {
      // this.getList();
    }
  },

  frmClick(e) {
    app.saveFormId(e.detail.formId);
  },

  onSure() {
    var page = this;
    app.sendRequest({
      url: app.api.public.focus,
      data: {
        content_id: page.data.focus_id,
        type: page.data.focus_type
      },
      method: 'POST',
      header: {
        token: wx.getStorageSync('access_token'),
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function(res) {
        page.setData({ actionSheetHidden: !page.data.actionSheetHidden });
        page.onShow();
      }
    });
    
  },
 
  actionSheetChange() {
    this.setData({ actionSheetHidden: !this.data.actionSheetHidden });
  },

  toFocus: function(e) {
    var focus_id = e.currentTarget.dataset.id;
    var focus_type = e.currentTarget.dataset.type;

    this.setData({
      actionSheetHidden: !this.data.actionSheetHidden,
      focus_type: focus_type,
      focus_id: focus_id,
    });
  },

  toTeacherDetail: function(e) {
    var teacher_id = e.currentTarget.dataset.id;
    var teacher_title = e.currentTarget.dataset.title;
    var name = e.currentTarget.dataset.name;
    var logging = wx.getStorageSync('_logining');
    if (!logging) {
      app.toAuth('/' + this.route);
    } else {
      wx.navigateTo({
        url:
          '../teacher_detail/teacher_detail?teacher_id=' +
          teacher_id +
          '&teacher_title=' +
          teacher_title +
          '&name=' +
          name
      });
    }
  },

  toSchoolDetail: function (e) {
    var school_id = e.currentTarget.dataset.id;
    var school_name = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: '../school_detail/school_detail?school_id=' + school_id + '&school_name=' + school_name,
    })
  },

  //  列表数据
  getList: function() {
    var obj = this;
    let current_user_id = wx.getStorageSync('current_user_id');
    //  关注名校列表
    app.sendRequest({
      url: api.school.list,
      data: {
        focus: 1 ,
        user_id: current_user_id 
      },
      success: function (res) {
        if (JSON.stringify(res.data) !== '{}') {
          // 设置数据  
          obj.setData({
            famous_school: res.data.list
          })
        } else {
          obj.setData({
            famous_school: []
          })
        }

      },
    });

    //  关注名师列表
    app.sendRequest({
      url: api.teacher.student_teacher_focus_list,
      success: function (res) {
        if (JSON.stringify(res.data) !== '{}') {
          // 设置数据  
          obj.setData({
            famous_teacher: res.data.list
          })
        } else {
          obj.setData({
            famous_teacher: []
          })
        }

      },
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var logging = wx.getStorageSync('_logining');
    if (logging) {
      this.getList();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})